package com.sunbim.rsrv.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 接口文档 swagger配置
 */
@Configuration
public class SwaggerConfig {

    // 第一组接口
    @Bean
    public Docket v1(Environment environment) {
        // 检测环境是否为dev或test
        Profiles profiles = Profiles.of("dev", "test");
        environment.acceptsProfiles(profiles);

        ApiInfo info = new ApiInfoBuilder()
                .title("接口文档v1")
                .description("v1版本接口文档")
                .contact(new Contact("yuhui", "", ""))
                .version("1.0")
                .build();
        // 创建docket
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(info)
                .groupName("v1")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sunbim.rsrv.controller.v1")) // 按包筛选
                .paths(PathSelectors.any()) // 路径筛选  PathSelectors.ant("/api/v1/**")
                .build();
    }

    // 第二组接口
    // @Bean
    // public Docket v2() {
    // }
}